package com.jims.api.interceptor;

import com.jims.master.common.utils.IpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局拦截
 */
public class ApiInterceptor extends HandlerInterceptorAdapter {


	private static final Logger LOG = LoggerFactory.getLogger(ApiInterceptor.class);

	/**
	 * 入拦截
	 * @param req
	 * @param res
	 * @param handler
	 * @return
	 */
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler){

		/*LOG.debug("请求URL--->{}---->requesID---->开始",req.getRequestURL(),req.getRequestedSessionId());
		LOG.debug("{}<------访问IP------>{}","拦截器进入", IpUtil.getIpAddress(req));*/
		//权限拦截









		//权限错误
		/*LOG.error("{}<------访问IP------>{}","拦截器异常",IpUtil.getIpAddress(req));*/





		//权限通过
		/*LOG.debug("{}<------访问IP------>{}","拦截器通过",IpUtil.getIpAddress(req));*/
		return true;
	}

	/**
	 * 出拦截
	 * @param req
	 * @param response
	 * @param handler
	 * @param modelAndView
	 * @throws Exception
	 */
	/*@Override
	public void postHandle(
			HttpServletRequest req, HttpServletResponse response, Object handler, ModelAndView modelAndView)
			throws Exception {

		LOG.debug("请求URL--->{}---->requesID---->结束",req.getRequestURL(),req.getRequestedSessionId());
	}*/
}
